package com.jumi.microservice.service.taobao;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.jumi.microservice.dto.taobao.TaoBaoOrder;
import com.jumi.microservice.service.ITaoBaoAdminService;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Dirk
 * @Date 2021-01-13 15:45
 */
public class TaoBaoOrderExcelListener extends AnalysisEventListener<TaoBaoOrder> {

    private final ITaoBaoAdminService taoBaoAdminService;

    private final List<TaoBaoOrder> taoBaoOrderList  = new ArrayList<>();

    public TaoBaoOrderExcelListener(ITaoBaoAdminService taoBaoAdminService) {
        this.taoBaoAdminService = taoBaoAdminService;
    }

    @Override
    public void invoke(TaoBaoOrder taoBaoOrder, AnalysisContext analysisContext) {
        taoBaoOrderList.add(taoBaoOrder);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {
        taoBaoAdminService.importOrderExcel(taoBaoOrderList);
    }
}
